<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="10" :lg="11" :md="12" :sm="24">
            <a-form-item :label="$t('时间')">
              <j-date
                :show-time="{ defaultValue: moment('00:00:00', 'HH:mm:ss') }"
                valueFormat="YYYY-MM-DD HH:mm:ss"
                dateFormat="YYYY-MM-DD HH:mm:ss"
                :placeholder="$t('请选择开始时间')"
                class="query-group-cust"
                v-model="queryParam.createTime_begin"
              ></j-date>
              <span class="query-group-split-cust"></span>
              <j-date
                :show-time="{ defaultValue: moment('23:59:59', 'HH:mm:ss') }"
                valueFormat="YYYY-MM-DD HH:mm:ss"
                dateFormat="YYYY-MM-DD HH:mm:ss"
                :placeholder="$t('请选择结束时间')"
                class="query-group-cust"
                v-model="queryParam.createTime_end"
              ></j-date>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item :label="$t('手机号')">
              <a-input :placeholder="$t('请输入会员手机号')" v-model="queryParam.phone"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('发送状态')">
                <a-select v-model="queryParam.state">
                  <a-select-option v-for="(item, index) in stateList" :key="index" :value="item.value">{{
                    item.title
                  }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">{{ $t('查询') }}</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">{{
                $t('重置')
              }}</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? $t('收起') : $t('展开') }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" icon="download" :loading="exloading" @click="handleExportXls($t('短信发送记录'))" v-has="'BisSmsRecordController:export'">{{
        $t('导出')
      }}</a-button>
      <a-button type="primary" icon="plus" @click="handleAdd" v-has="'BisSmsRecordController:send'">{{ $t('新增发送任务') }}</a-button>
      <a-button type="primary" @click="openCond" v-has="'BisSmsRecordController:send'">{{ $t('按会员画像发送') }}</a-button>
      <div class="cond-block cond-block1" v-if="cvisible">
        <div style="position: relative; height: -webkit-fill-available">
          <div class="custom-condition-content">
            <div class="cond-title">
              <span>{{ $t('筛选') }}</span>
              <a-icon type="close" @click="hide" />
            </div>
            <div style="margin: 10px 0; padding: 0 20px; white-space: break-spaces; text-align: left">
              <a-tag
                class="cond-tag"
                v-for="(cond, ind) in condItems"
                :key="cond.id"
                closable
                @close="delConds(cond, ind)"
              >
                <div class="cond-tag-content">
                  {{ $t(cond.columnName) }}：
                  <span v-if="cond.type == 1">{{ queryData[cond.columnId] }}</span>
                  <span v-if="cond.type == 2">{{
                    dictOptions[cond.data.data].filter((dt) => {
                      return dt[cond.data.value] == queryData[cond.columnId]
                    })[0][cond.data.text]
                  }}</span>
                  <span v-if="cond.type == 3">
                    <span v-for="(item, ind1) in queryData[cond.columnId]" :key="ind1">
                      {{
                        ind1 == 0
                          ? dictOptions[cond.data.data].filter((dt) => {
                              return dt[cond.data.value] == item
                            })[0][cond.data.text]
                          : ',' +
                            dictOptions[cond.data.data].filter((dt) => {
                              return dt[cond.data.value] == item
                            })[0][cond.data.text]
                      }}
                    </span>
                  </span>
                  <span v-if="cond.type == 4">
                    {{ queryData[cond.columnId + 'Query'] + queryData[cond.columnId] }}
                  </span>
                  <span v-if="cond.type == 7 || cond.type == 8">
                    <span v-for="(item, ind1) in cond.datas" :key="ind1">
                      {{
                        item.unit
                          ? item.type == 'select'
                            ? queryData[item.key] + item.unit
                            : item.unit
                          : item.type == 'select'
                          ? queryData[item.key]
                          : item.unit
                      }}
                    </span>
                  </span>
                  <span v-if="cond.type == 6">
                    {{
                      moment(queryData[cond.columnId + 'Begin']).format('YYYY-MM-DD') +
                      '~' +
                      moment(queryData[cond.columnId + 'End']).format('YYYY-MM-DD')
                    }}
                  </span>
                </div>
              </a-tag>
            </div>
            <div class="screen-condition" style="padding: 0 20px">
              <div style="margin-bottom: 10px" v-for="(cond, ind) in secItems" :key="ind">
                <div style="display: flex; justify-content: space-between; align-items: center; padding: 2px 0">
                  {{ $t(cond.columnName) }}<a-icon type="close" @click="delCond(ind)" style="color: #1890ff" />
                </div>
                <a-input v-model="queryData[cond.columnId]" v-if="cond.type == 1" />
                <a-select v-model="queryData[cond.columnId]" style="width: 100%" v-if="cond.type == 2">
                  <a-select-option value="">{{ $t('全部') }}</a-select-option>
                  <a-select-option
                    v-for="(item, ind) in dictOptions[cond.data.data]"
                    :key="ind"
                    :value="item[cond.data.value]"
                    >{{ item[cond.data.text] }}</a-select-option
                  >
                </a-select>
                <a-checkbox-group
                  v-model="queryData[cond.columnId]"
                  style="width: 100%; white-space: initial; text-align: left"
                  v-if="cond.type == 3"
                >
                  <a-checkbox
                    v-for="(item, ind) in dictOptions[cond.data.data]"
                    :key="ind"
                    :value="item[cond.data.value]"
                    style="width: 50%; vertical-align: top"
                    >{{ item[cond.data.text] }}</a-checkbox
                  >
                </a-checkbox-group>
                <div style="display: flex" v-if="cond.type == 4">
                  <a-select v-model="queryData[cond.columnId + 'Query']" style="width: 200px">
                    <a-select-option value=">">{{ $t('大于') }}</a-select-option>
                    <a-select-option value=">=">{{ $t('大于等于') }}</a-select-option>
                    <a-select-option value="=">{{ $t('等于') }}</a-select-option>
                    <a-select-option value="<=">{{ $t('小于等于') }}</a-select-option>
                    <a-select-option value="<">{{ $t('小于') }}</a-select-option>
                  </a-select>
                  <a-input v-model="queryData[cond.columnId]" style="margin-left: 4px" />
                  <span style="padding: 2px" v-if="cond.unit">{{ cond.unit }}</span>
                </div>
                <div style="display: flex; align-items: center" v-if="cond.type == 7 || cond.type == 8">
                  <div v-for="(ele, ind1) in cond.datas" :key="ind1" :style="{ width: ele.width }">
                    <a-select
                      v-show="ele.type == 'select'"
                      v-model="queryData[ele.key]"
                      @change="ele.changeEvent"
                      style="width: 100%"
                    >
                      <a-select-option
                        v-for="(item, ind2) in ele.data"
                        :key="ind2"
                        :value="item.value ? item.value : item"
                        >{{
                          ele.unit ? (item.text ? item.text : item) + ele.unit : item.text ? item.text : item
                        }}</a-select-option
                      > </a-select
                    ><span v-show="ele.type == 'text'" style="padding: 2px">{{ ele.unit }}</span>
                  </div>
                </div>
                <div style="display: flex; align-items: center" v-if="cond.type == 6">
                  <a-date-picker
                    v-model="queryData[cond.columnId + 'Begin']"
                    format="YYYY-MM-DD"
                    value-format="YYYY-MM-DD 00:00:00"
                  ></a-date-picker>
                  <span style="padding: 2px">~</span>
                  <a-date-picker
                    v-model="queryData[cond.columnId + 'End']"
                    format="YYYY-MM-DD"
                    value-format="YYYY-MM-DD 23:59:59"
                  ></a-date-picker>
                </div>
              </div>
            </div>
          </div>
          <div class="cond-btn">
            <div style="display: flex; justify-content: space-between">
              <div @click="moreCond" style="padding: 4px 0; text-align: left; color: #1890ff">
                {{ $t('更多条件') }}
              </div>
              <div>
                <a-button
                  @click="resetCondition"
                  style="margin-right: 6px; background-color: #fff; border-color: #169bd5; color: #169bd5"
                  >{{ $t('清除条件') }}</a-button
                ><a-button
                  @click="screenCondition"
                  style="background-color: #169bd5; border-color: #169bd5; color: #fff"
                  >{{ $t('筛选') }}</a-button
                >
              </div>
            </div>
            <div style="padding: 4px 0; border-bottom: 1px solid #ccc">
              <i18n path="condition-sms" tag="span">
                <span place="memnum" style="padding: 0 4px; color: red; font-weight: 800; font-size: 18px">{{ memNum }}</span>
                <span place="phonenum" style="padding: 0 2px; color: red; font-weight: 800; font-size: 18px">{{ phoneNum }}</span>
              </i18n>
            </div>
            <div style="padding: 6px 0">
              <a-textarea v-model="eachNumber" :placeholder="$t('请输入短信内容')" :rows="2" />
            </div>
            <div>
              <a-button
                :disabled="confirmLoading"
                @click="sendSMS"
                style="
                  margin: 0;
                  color: #fff;
                  background-color: rgb(20, 203, 151);
                  border-color: rgb(20, 203, 151);
                "
                >{{ $t('发送') }}</a-button
              >
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true }"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">{{ $t('无图片') }}</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt=""
            style="max-width: 80px; font-size: 12px; font-style: italic"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">{{ $t('无文件') }}</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            {{ $t('下载') }}
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">{{ $t('编辑') }}</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">{{ $t('更多') }} <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">{{ $t('详情') }}</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm :title="$t('确定删除吗?')" @confirm="() => handleDelete(record.id)">
                  <a>{{ $t('删除') }}</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>

    <bis-sms-record-modal ref="modalForm" @ok="modalFormOk"></bis-sms-record-modal>
    <more-cond-modal
      ref="moreCondModal"
      @setCond="getCondData"
      :setconds="formItems"
      :setcondsgroup="setcolumnsgroup"
      :secConds="secConds"
    ></more-cond-modal>
  </a-card>
</template>

<script>
import moment from 'moment'
import '@/assets/less/TableExpand.less'
import { getAction, postAction } from '@/api/manage'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { initDictOptions } from '@/components/dict/JDictSelectUtil'
import BisSmsRecordModal from './modules/BisSmsRecordModal'
import MoreCondModal from '../marketingmanage/modules/MoreCondModal'
var f = (length, num) => Array.from({ length }).map((v, k) => k + num)

export default {
  name: 'BisSmsRecordList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    BisSmsRecordModal,
    MoreCondModal,
  },
  data() {
    return {
      moment,
      description: '短信发送记录管理页面',
      // 表头
      columns: [
        {
          title: this.$t('发送时间'),
          align: 'center',
          dataIndex: 'createTime',
        },
        {
          title: this.$t('手机号'),
          align: 'center',
          dataIndex: 'phone',
        },
        {
          title: this.$t('短信内容'),
          align: 'center',
          dataIndex: 'content',
        },
        {
          title: this.$t('发送状态'),
          align: 'center',
          dataIndex: 'state_dictText',
        },
        {
          title: this.$t('失败原因'),
          align: 'center',
          dataIndex: 'errorMsg',
        },
        {
          title: this.$t('操作员'),
          align: 'center',
          dataIndex: 'createBy',
        },
        // {
        //   title: '操作',
        //   dataIndex: 'action',
        //   align:"center",
        //   fixed:"right",
        //   width:147,
        //   scopedSlots: { customRender: 'action' }
        // }
      ],
      url: {
        list: '/system/bisSmsRecord/list',
        delete: '/system/bisSmsRecord/delete',
        deleteBatch: '/system/bisSmsRecord/deleteBatch',
        exportXlsUrl: '/system/bisSmsRecord/exportXls',
        importExcelUrl: 'system/bisSmsRecord/importExcel',
      },
      stateList: [],
      queryParam: {
        state: '',
      },
      cvisible: false,
      monthList: f(12, 1),
      yearList: f(moment().year() - 1899, 1900),
      dayList: [],
      regDayList: [],
      memNum: 0,
      phoneNum: 0,
      queryData: {},
      eachNumber: '',
      setcolumnsgroup: [],
      defItems: [],
      secItems: [],
      condItems: [],
      secConds: [],
      formItems: [],
      confirmLoading: false,
      dictOptions: {
        sex: [],
        source: [],
        channel: [],
        memberTypes: [],
      },
    }
  },
  created() {
    this.getSuperFieldList()
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    initDictConfig() {
      let that = this
      initDictOptions('bis_sms_record.state').then((res) => {
        if (res.success) {
          that.stateList = res.result
          that.stateList.unshift({ title: that.$t('全部'), value: '' })
        }
      })
      initDictOptions('bis_member.sex').then((res) => {
        if (res.success) {
          that.$set(that.dictOptions, 'sex', res.result)
          that.dictOptions.sex.unshift({ value: '', text: that.$t('全部') })
        }
      })
      initDictOptions('bis_member_infor.source').then((res) => {
        if (res.success) {
          that.$set(that.dictOptions, 'source', res.result)
        }
      })
      initDictOptions('bis_device_info.type').then((res) => {
        if (res.success) {
          that.$set(that.dictOptions, 'channel', res.result)
        }
      })
      getAction('/member/bisMemberRule/list', { notNonmember: 1, manageState: 'Y', pageSize: 40 }).then((res) => {
        if (res.success) {
          let result = res.result.records.map((rds) => {
            let dtl = {
              value: rds.id,
              text: rds.name,
            }
            return dtl
          })
          that.$set(that.dictOptions, 'memberTypes', result)
          return
        }
      })
      that.getMemberDraw()
    },
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'datetime', value: 'createTime', text: this.$t('发送时间') })
      fieldList.push({ type: 'string', value: 'phone', text: this.$t('手机号'), dictCode: '' })
      fieldList.push({ type: 'string', value: 'content', text: this.$t('短信内容'), dictCode: '' })
      fieldList.push({ type: 'int', value: 'state', text: this.$t('发送状态'), dictCode: 'bis_sms_record.state' })
      fieldList.push({ type: 'string', value: 'errorMsg', text: this.$t('失败原因'), dictCode: '' })
      fieldList.push({ type: 'string', value: 'createBy', text: this.$t('操作员'), dictCode: '' })
      this.superFieldList = fieldList
    },
    getMemberDraw() {
      let that = this
      getAction('/query/bisQuery/getByTitle', { title: 'memberInfoDrawing' }).then((res) => {
        if (res.success) {
          let arr = res.result.records,
            arr1 = [],
            arr2 = [],
            arr3 = []
          that.setcolumnsgroup = []
          arr.forEach((a, i) => {
            let dtl = {
              id: a.id,
              name: a.name,
              sort: a.sort,
              col: i <= 1 ? 5 : 4,
            }
            if (!a.isHidden) {
              dtl.bisQueryItemList = a.bisQueryItemList.filter((bq) => {
                return bq.isHidden == 0
              })
              arr1.push(dtl)
              dtl.bisQueryItemList.forEach((bq) => {
                if (bq.isDefault) {
                  arr2.push(bq.columnId)
                }
              })
            }
            a.bisQueryItemList.forEach((bq) => {
              if (bq.columnId == 'sex') {
                bq.data = { data: 'sex', value: 'value', text: 'text' }
              }
              if (bq.columnId == 'birthday') {
                bq.datas = [
                  {
                    key: 'birthMonth1',
                    data: f(12, 1),
                    unit: that.$t('月'),
                    type: 'select',
                    changeEvent: that.changeBirthMonth,
                    width: '25%',
                  },
                  { key: 'birthDay1', data: f(31, 1), unit: that.$t('日'), type: 'select', width: '25%' },
                  { unit: '~', type: 'text', width: '20px' },
                  {
                    key: 'birthMonth2',
                    data: f(12, 1),
                    unit: that.$t('月'),
                    type: 'select',
                    changeEvent: that.changeBirthMonth,
                    width: '25%',
                  },
                  { key: 'birthDay2', data: f(31, 1), unit: that.$t('日'), type: 'select', width: '25%' },
                ]
              }
              if (bq.columnId == 'sources') {
                bq.data = { data: 'source', value: 'value', text: 'text' }
              }
              if (bq.columnId == 'regChannels') {
                bq.data = { data: 'channel', value: 'value', text: 'text' }
              }
              if (bq.columnId == 'memberTypes') {
                bq.data = { data: 'memberTypes', value: 'value', text: 'text' }
              }
              if (bq.columnId == 'regHowFar') {
                bq.datas = [
                  {
                    key: 'regHowFarQuery',
                    data: [
                      { value: '>', text: this.$t('大于') },
                      { value: '>=', text: this.$t('大于等于') },
                      { value: '=', text: this.$t('等于') },
                      { value: '<=', text: this.$t('小于等于') },
                      { value: '<', text: this.$t('小于') },
                    ],
                    type: 'select',
                    width: '160px',
                  },
                  {
                    key: 'regYaer',
                    data: f(moment().year() - 1899, 1900),
                    type: 'select',
                    changeEvent: this.changeRegYear,
                    width: '30%',
                  },
                  { unit: this.$t('年'), type: 'text', width: '30px' },
                  {
                    key: 'regMonth',
                    data: f(12, 1),
                    type: 'select',
                    changeEvent: this.changeRegMonth,
                    width: '20%',
                  },
                  { unit: this.$t('月'), type: 'text', width: '30px' },
                  {
                    key: 'regDay',
                    data: f(31, 1),
                    type: 'select',
                    width: '20%',
                  },
                  { unit: this.$t('日'), type: 'text', width: '30px' },
                ]
              }
              arr3.push(bq)
            })
          })
          that.setcolumnsgroup = arr1
          that.defItems = arr2
          that.formItems = arr3
          if (
            localStorage.getItem('mScreenCondSMS') != undefined &&
            localStorage.getItem('mScreenCondSMS') != null &&
            localStorage.getItem('mScreenCondSMS') != ''
          ) {
            that.secItems = JSON.parse(localStorage.getItem('mScreenCondSMS'))
          } else {
            that.secItems = []
            that.defItems.forEach((dt) => {
              let obj = that.formItems.filter((ft) => {
                return ft.columnId == dt
              })[0]
              that.secItems.push(obj)
            })
          }
          that.secConds = []
          that.secItems.forEach((si) => {
            that.secConds.push(
              that.formItems.filter((ft) => {
                return ft.columnId == si.columnId
              })[0]
            )
          })
          if (
            localStorage.getItem('mQueryDataCoupon') != undefined &&
            localStorage.getItem('mQueryDataCoupon') != null &&
            localStorage.getItem('mQueryDataCoupon') != ''
          ) {
            that.queryData = JSON.parse(localStorage.getItem('mQueryDataCoupon'))
          } else {
            that.queryData = {
              sex: '',
              coinQuery: '>',
              lotteryQuery: '>',
              integralQuery: '>',
              aCoinQuery: '>',
              aLotteryQuery: '>',
              voucherCountQuery: '>',
              ticketCountQuery: '>',
              ticketNumInOneYearQuery: '>',
              limitCoinCountQuery: '>',
              arrivalStoreInThreeMonthQuery: '>',
              arrivalStoreInOneYearQuery: '>',
              sumConsumeAmountInThreeMonthQuery: '>',
              sumConsumeAmountInOneYearQuery: '>',
              avgConsumeAmountInThreeMonthQuery: '>',
              avgConsumeAmountInOneYearQuery: '>',
              lastConsumeHowFarQuery: '>',
              storedValueNumQuery: '>',
              sumRechargePriceQuery: '>',
              sumRechargeCoinQuery: '>',
              lastRechargeAmountQuery: '>',
              regHowFarQuery: '>',
              loginNumInOneMonthQuery: '>',
              shareNumInOneMonthQuery: '>',
            }
          }
          that.screenCondition()
        }
      })
    },
    screenCondition() {
      let that = this
      if (
        that.queryData.birthMonth1 &&
        that.queryData.birthMonth2 &&
        that.queryData.birthDay1 &&
        that.queryData.birthDay2
      ) {
        that.queryData.birthdayBegin = that.queryData.birthMonth1 + '-' + that.queryData.birthDay1
        that.queryData.birthdayEnd = that.queryData.birthMonth2 + '-' + that.queryData.birthDay2
      }
      if (that.queryData.regYaer && that.queryData.regMonth && that.queryData.regDay) {
        let m1 = moment()
        let m2 = moment(
          that.queryData.regYaer + '-' + that.queryData.regMonth + '-' + that.queryData.regDay,
          'YYYY-MM-DD'
        )
        that.queryData.regHowFar = m1.diff(m2, 'day')
      }
      that.condItems = []
      for (var key in that.queryData) {
        if (key.indexOf('Query') < 0) {
          let datas = []
          if (key.indexOf('Begin') > -1) {
            key = key.replace('Begin', '')
            datas = that.secItems.filter((si) => {
              return si.columnId == key
            })
          } else {
            datas = that.secItems.filter((si) => {
              return si.columnId == key
            })
          }
          if (datas.length > 0) {
            that.condItems.push(datas[0])
          }
        }
      }
      localStorage.setItem('mQueryDataCoupon', JSON.stringify(that.queryData))
      that.getCondMember()
    },
    getCondMember() {
      //获取所有符合条件的会员或会员数量
      let that = this
      let query = Object.assign({}, { isQs: true }, this.queryData)
      let regHowFarQuery = query.regHowFarQuery
      query.regHowFarQuery =
        regHowFarQuery == '>'
          ? '<='
          : regHowFarQuery == '>='
          ? '<'
          : regHowFarQuery == '<='
          ? '>'
          : regHowFarQuery == '<'
          ? '>='
          : '='
      if (query.sex == '') {
        delete query.sex
      }
      let getItems = []
      for (var key in that.queryData) {
        let x = that.secItems.findIndex((si) => {
          return si.columnId == key || si.columnId + 'Begin' == key
        })
        if (that.queryData[key] != '' && x > -1) {
          let dtl = that.secItems[x],
            obj = {}
          obj.queryItemId = dtl.id
          if (dtl.queryResultId) {
            obj.id = dtl.queryResultId
          }
          if (dtl.type == 1 || dtl.type == 2) {
            obj.firstValue = that.queryData[key]
          }
          if (dtl.type == 3) {
            obj.checkList = []
            that.queryData[key].forEach((qd) => {
              obj.checkList.push({
                checkId: qd,
              })
            })
          }
          if (dtl.type == 4 || dtl.type == 5) {
            obj.firstValue = that.queryData[key + 'Query']
            obj.secondValue = that.queryData[key]
          }
          if (dtl.type == 6 || dtl.type == 7) {
            obj.firstValue = that.queryData[key]
            obj.secondValue = that.queryData[key.slice(0, key.length - 5) + 'End']
          }
          if (dtl.type == 8) {
            obj.firstValue = that.queryData[key + 'Query']
            obj.secondValue = that.queryData[key]
            if (that.queryData[key + '1'] == undefined || that.queryData[key + '1'] == null) {
              that.queryData[key + '1'] = ''
            }
            if (that.queryData[key + '2'] == undefined || that.queryData[key + '2'] == null) {
              that.queryData[key + '2'] = ''
            }
            if (that.queryData[key + '3'] == undefined || that.queryData[key + '3'] == null) {
              that.queryData[key + '3'] = ''
            }
            obj.thirdValue =
              that.queryData[key + '1'] + ',' + that.queryData[key + '2'] + ',' + that.queryData[key + '3']
          }
          getItems.push(obj)
        }
      }
      postAction('/member/bisManualCouponRecord/getDrawingTotal', { queryItems: getItems }).then((res) => {
        if (res.success) {
          that.memNum = res.result.total
          that.phoneNum = res.result.phoneCount
          return
        }
        that.$message.error(res.message)
      })
    },
    hide() {
      this.cvisible = false
    },
    openCond() {
      let that = this
      getAction('/bis/bisSysParameter/queryByName', { name: 'shumiAccountId' }).then((res0) => {
        /* if(res0.success&&res0.result.svalue=='400637'){
          that.$message.warning(that.$t('请先联系数米公司开通短信账户；联系方式：程女士，电话18611733312 或 微信号 Cgm_jiayou'))
          return
        }
        if (res0.success && res0.result.svalue != '400637') { */
          that.cvisible = true
          that.eachNumber = ''
          that.confirmLoading = false
          if (
            localStorage.getItem('mQueryDataCoupon') != undefined &&
            localStorage.getItem('mQueryDataCoupon') != null &&
            localStorage.getItem('mQueryDataCoupon') != ''
          ) {
            that.queryData = JSON.parse(localStorage.getItem('mQueryDataCoupon'))
          } else {
            that.queryData = {
              sex: '',
              coinQuery: '>',
              lotteryQuery: '>',
              integralQuery: '>',
              aCoinQuery: '>',
              aLotteryQuery: '>',
              voucherCountQuery: '>',
              ticketCountQuery: '>',
              ticketNumInOneYearQuery: '>',
              limitCoinCountQuery: '>',
              arrivalStoreInThreeMonthQuery: '>',
              arrivalStoreInOneYearQuery: '>',
              sumConsumeAmountInThreeMonthQuery: '>',
              sumConsumeAmountInOneYearQuery: '>',
              avgConsumeAmountInThreeMonthQuery: '>',
              avgConsumeAmountInOneYearQuery: '>',
              lastConsumeHowFarQuery: '>',
              storedValueNumQuery: '>',
              sumRechargePriceQuery: '>',
              sumRechargeCoinQuery: '>',
              lastRechargeAmountQuery: '>',
              regHowFarQuery: '>',
              loginNumInOneMonthQuery: '>',
              shareNumInOneMonthQuery: '>',
            }
            that.memNum = 0
            that.phoneNum = 0
          }
          that.condItems = []
          for (var key in that.queryData) {
            if (key.indexOf('Query') < 0) {
              let datas = []
              if (key.indexOf('Begin') > -1) {
                key = key.replace('Begin', '')
                datas = that.secItems.filter((si) => {
                  return si.columnId == key
                })
              } else {
                datas = that.secItems.filter((si) => {
                  return si.columnId == key
                })
              }
              if (datas.length > 0) {
                that.condItems.push(datas[0])
              }
            }
         /*  } */
        }
      })
    },
    moreCond() {
      this.$refs.moreCondModal.edit()
    },
    delCond(ind) {
      this.secItems.splice(ind, 1)
      this.secConds = []
      this.secItems.forEach((si) => {
        this.secConds.push(
          this.formItems.filter((sc) => {
            return sc.columnId == si.columnId
          })[0]
        )
      })
      localStorage.setItem('mScreenCondSMS', JSON.stringify(this.secItems))
    },
    delConds(item, i) {
      let that = this
      if (item.type == 6) {
        delete that.queryData[item.columnId + 'Begin']
        delete that.queryData[item.columnId + 'End']
      } else if (item.type == 7) {
        delete that.queryData[item.columnId + 'Begin']
        delete that.queryData[item.columnId + 'End']
        item.datas.forEach((ds) => {
          if (ds.type == 'select' && ds.key.indexOf('Query') < 0) {
            delete that.queryData[ds.key]
          }
        })
      } else if (item.columnId == 'sex') {
        that.queryData.sex = ''
      } else if (item.columnId == 'regHowFar') {
        that.queryData.regHowFarQuery = '>'
        delete that.queryData.regYaer
        delete that.queryData.regMonth
        delete that.queryData.regDay
        delete that.queryData.regHowFar
      } else {
        delete that.queryData[item.columnId]
      }
      that.condItems.splice(i, 1)
      localStorage.setItem('mQueryDataCoupon', JSON.stringify(that.queryData))
      that.getCondMember()
    },
    resetCondition() {
      this.queryData = {
        sex: '',
        coinQuery: '>',
        lotteryQuery: '>',
        integralQuery: '>',
        aCoinQuery: '>',
        aLotteryQuery: '>',
        voucherCountQuery: '>',
        ticketCountQuery: '>',
        ticketNumInOneYearQuery: '>',
        limitCoinCountQuery: '>',
        arrivalStoreInThreeMonthQuery: '>',
        arrivalStoreInOneYearQuery: '>',
        sumConsumeAmountInThreeMonthQuery: '>',
        sumConsumeAmountInOneYearQuery: '>',
        avgConsumeAmountInThreeMonthQuery: '>',
        avgConsumeAmountInOneYearQuery: '>',
        lastConsumeHowFarQuery: '>',
        storedValueNumQuery: '>',
        sumRechargePriceQuery: '>',
        sumRechargeCoinQuery: '>',
        lastRechargeAmountQuery: '>',
        regHowFarQuery: '>',
        loginNumInOneMonthQuery: '>',
        shareNumInOneMonthQuery: '>',
      }
      localStorage.removeItem('mQueryDataCoupon')
      this.condItems = []
      this.memNum = 0
      this.phoneNum = 0
    },
    getCondData(val) {
      let that = this
      that.secItems = []
      val.forEach((v) => {
        let dtl = that.formItems.filter((ft) => {
          return ft.columnId == v.columnId
        })[0]
        dtl.sort = v.sort
        that.secItems.push(dtl)
      })
      that.secConds = []
      that.secItems.forEach((si) => {
        let dtl = that.formItems.filter((ft) => {
          return ft.columnId == si.columnId
        })[0]
        dtl.sort = si.sort
        that.secConds.push(dtl)
      })
      localStorage.setItem('mScreenCondSMS', JSON.stringify(that.secItems))
    },
    sendSMS() {
      let that = this,
        query = {}
      if (that.eachNumber === 0 || that.eachNumber === '') {
        that.$message.error(that.$t('请输入发送内容'))
        return
      }
      that.confirmLoading = true
      query.content = that.eachNumber
      let queryData = Object.assign({}, that.queryData)
      let regHowFarQuery = queryData.regHowFarQuery
      queryData.regHowFarQuery =
        regHowFarQuery == '>'
          ? '<='
          : regHowFarQuery == '>='
          ? '<'
          : regHowFarQuery == '<='
          ? '>'
          : regHowFarQuery == '<'
          ? '>='
          : '='
      if (queryData.sex == '') {
        delete queryData.sex
      }
      let getItems = []
      for (var key in queryData) {
        let x = that.secItems.findIndex((si) => {
          return si.columnId == key || si.columnId + 'Begin' == key
        })
        if (queryData[key] != '' && x > -1) {
          let dtl = that.secItems[x],
            obj = {}
          obj.queryItemId = dtl.id
          if (dtl.queryResultId) {
            obj.id = dtl.queryResultId
          }
          if (dtl.type == 1 || dtl.type == 2) {
            obj.firstValue = that.queryData[key]
          }
          if (dtl.type == 3) {
            obj.checkList = []
            queryData[key].forEach((qd) => {
              obj.checkList.push({
                checkId: qd,
              })
            })
          }
          if (dtl.type == 4 || dtl.type == 5) {
            obj.firstValue = queryData[key + 'Query']
            obj.secondValue = queryData[key]
          }
          if (dtl.type == 6 || dtl.type == 7) {
            obj.firstValue = queryData[key]
            obj.secondValue = queryData[key.slice(0, key.length - 5) + 'End']
          }
          if (dtl.type == 8) {
            obj.firstValue = queryData[key + 'Query']
            obj.secondValue = queryData[key]
            if (queryData[key + '1'] == undefined || queryData[key + '1'] == null) {
              queryData[key + '1'] = ''
            }
            if (queryData[key + '2'] == undefined || queryData[key + '2'] == null) {
              queryData[key + '2'] = ''
            }
            if (queryData[key + '3'] == undefined || queryData[key + '3'] == null) {
              queryData[key + '3'] = ''
            }
            obj.thirdValue = queryData[key + '1'] + ',' + queryData[key + '2'] + ',' + queryData[key + '3']
          }
          getItems.push(obj)
        }
      }
      query.queryItems = getItems
      postAction('/system/bisSmsRecord/sendByDrawing', query)
        .then((res) => {
          if (res.success) {
            that.$message.success(that.$t('发送成功'))
            that.hide()
            that.searchQuery()
          } else {
            that.$message.error(res.message)
          }
        })
        .finally(() => {
          that.confirmLoading = false
        })
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>

<style scoped>
.cond-block {
  position: fixed;
  background-color: #fff;
  z-index: 10;
  right: 20px;
  bottom: 20px;
  top: 120px;
  width: 400px;
  box-shadow: 0 0 6px rgba(3, 3, 3, 0.5);
}
.cond-block1 .custom-condition-content {
  position: absolute;
  top: 0;
  bottom: 220px;
  left: 0;
  right: 0;
  padding-bottom: 20px;
  background-color: #fff;
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.custom-condition-content::-webkit-scrollbar {
  width: 0px;
  display: none;
}
.cond-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  border-bottom: 1px solid #eee;
}
.ant-tag.cond-tag {
  margin-bottom: 4px;
  background-color: #f59b1e;
  border-color: #f59b1e;
}
.cond-tag-content {
  color: #fff;
  display: inline-block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 330px;
  vertical-align: top;
}
.screen-condition .ant-checkbox-wrapper + .ant-checkbox-wrapper {
  margin-left: 0;
}
.cond-btn {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: #fff;
  padding: 10px 20px;
  border-top: 1px solid #eee;
  z-index: 11;
  text-align: left;
}
.custom-condition-content .ant-tag .anticon-close {
  color: red;
}
</style>